<template>
  <view class="p-goods-list">
    <view
      class="_goods-detail"
      v-for="(item, index) in list"
      :key="index"
      :id="'pid' + index"
      @click="onDetail(item)"
    >
      <view class="_goods-img">
        <x-image :src="formatOss(item.productMainPic)" />
      </view>
      <view class="_goods-title">
        <view class="_goods_name">{{item.productTitle}}</view>
        <view class="_goods-price">
          <text style="margin-right: 2px;">¥</text>
          <text>{{ item.productPrice }}</text>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
import $sr from '@/utils/x-sr';
import XImage from '@/components/x-image';

export default {
  name: 'PGoodsList',
  components: {
    XImage
  },
  props: {
    list: {
      type: Array,
      default: () => []
    }
  },
  data() {
    return {};
  },
  methods: {
    // 格式化图片
    formatOss(url) {
      return this.$tools.formatOss(url, 300);
    },
    onDetail(item) {
      $sr.trackProductCard('trigger_sku_component', item);
      uni.navigateTo({
        url: `/pages/goods-detail/index?productId=${item.productId}`
      });
    }
  }
};
</script>

<style lang="scss">
.p-goods-list{
  display: flex;
  //justify-content: space-between;
  flex-wrap: wrap;
  ._goods-detail{
    box-sizing: border-box;
    width: 223px;
    // min-height: 540px;
    border-radius: 10px;
    overflow: hidden;
    margin-bottom: 16px;
    margin-right: 16px;
    ._goods-img{
      position: relative;
      width: 223px;
      height: 223px;
      ._tips{
        position: absolute;
        top: 10px;
        left: 0;
        min-width: 72px;
        height: 36px;
        line-height: 36px;
        font-size: 24px;
        text-align: center;
        color: #fff;
        background: linear-gradient(270deg, #FF2725 0%, #FF761C 100%);
        border-radius: 0px 50px 50px 0px;
      }
    }
    ._goods-title{
      background: #fff;
      padding: 10px 0 20px 0;
      ._goods_name{
        min-height: 70px;
        line-height: 1.5;
        color: #323233;
        font-size: 26px;
        -webkit-line-clamp: 2;
        display: -webkit-box;
        -webkit-box-orient: vertical;
        overflow: hidden;
        text-overflow: ellipsis;
      }
      ._goods-price{
        font-weight: bold;
        font-size: 28px;
        color: $uni-color-primary;
        ._blod{
          font-size: 36px;
          font-weight: bold;
        }
        ._decoration{
          text-decoration:line-through;
          color: #999999;
          margin-left: 5px;
        }
      }
    }
  }
  ._goods-detail:nth-child(3n) {
    margin-right: 0;
  }
}
</style>
